<?php
function view_bcksanggar($config,$param) {
    $db = new db($config);
    $result = $db->query("SELECT * FROM sanggar WHERE 1");
	$desc = $db->query("SELECT * FROM deskripsi WHERE page ='sanggar'");
    $param['sanggar'] = true;
    $param['loggedin'] = true;
    view_backend_header($config, $param);
    ?>
    <?php
    //verifikasi isian gunakan javascript
    if (isset($_SESSION['editted'])) {
        echo '<div class="alert alert-warning">'.$_SESSION['editted'].'</div>';
        unset($_SESSION['editted']);
    }
    ?>
    <div>
        <form method="post" action="<?php echo $config['home_url']."backend/edsanggar"?>">
            <div>Deskripsi : <textarea class="descbck" name="descsanggar"><?php echo $desc[0]['deskripsi']; ?></textarea>
            <div><input class="btn" type="submit" value="Ubah" name="ubah" /></div>
        </form>
    </div>
    <h3 onclick="javascript:showHide('komunitas');">Komunitas++</h3>
    <div id="komunitas" style="display:none">
        <form method="post" action="<?php echo $config['home_url']."backend/edsanggarkomu"?>" enctype="multipart/form-data">
            <div>Komunitas : <input style="width:400px" type="text" name="komuplus" /></div>
			Link komunitas : <div class="input-prepend"><span class="add-on">http://</span><input style="width:300px" type="text" name="linkplus" /></div>
			<div>Deskripsi : <textarea class="descbck" name="descplus"></textarea></div>
			<div>Profpict : <input type="file" name="ppplus" /></div>
            <div><input class="btn" type="submit" value="Tambah" name="tambah" /></div>
        </form>
		<div>
			<?php
			echo "<ul>";
			foreach ($result as $res){
				//echo "<li><a href=\"".$config['home_url']."backend/aboutus/".$res['idAbout']."\">".$res['nama']."</a></li>";
				echo "<li><a href=\"javascript:showHide('sg".$res['idSanggar']."');\">".$res['komunitas']."</a> <a href=\"".$config['home_url']."backend/delsanggarkomu/".$res['idSanggar']."\">(X)</a>";
				echo "<div style=\"display:none\"id=\"sg".$res['idSanggar']."\">";
					//echo $config['home_url']."backend/kutipan/".$res['idkutipan'];
					echo "<form method=\"post\" action=\"".$config['home_url']."backend/edsanggarkomu"."\">";
						echo "<input type=\"hidden\" name=\"id\" value=\"".$res['idSanggar']."\" />";
						echo "<div>Komunitas : <input style=\"width:400px\" type=\"text\" name=\"komued\" value=\"".$res['komunitas']."\" /></div>";
						echo "Link komunitas : <div class=\"input-prepend\"><span class=\"add-on\">http://</span><input style=\"width:300px\" type=\"text\" name=\"linked\" value=\"".$res['link']."\" /></div>";
						echo "<div>Deskripsi : <textarea class=\"descbck\" name=\"desced\">".$res['deskripsi']."</textarea></div>";
						echo "<div><input class=\"btn\" type=\"submit\" value=\"Edit\" name=\"edit\" /></div>";
					echo "</form>";
				?>
					<div><?php
						$uploaddir = $config['image_path'].'sanggar'.DIRECTORY_SEPARATOR.'pp'.DIRECTORY_SEPARATOR;
						$cfiles = 0;
						$regex = $uploaddir.$res['idSanggar'].".*";
						//FILTER
						foreach (glob($regex) as $files) {
							$getFile = explode(DIRECTORY_SEPARATOR,$files);
							$file = $getFile[count($getFile)-1];
							?>
							<div id='download-thumb-<?php echo $cfiles; ?>'>
								<img id="gallery-thumb-img-<?php echo $cfiles; ?>" src="<?php echo $config['image_url']."sanggar/pp/".$file; ?>" alt="<?php echo $file; ?>" /> <a class="ahapus" href="<?php echo $config['home_url']."backend/delsanggarkomupp?img=$file"?>">(X)</a>
							</div>
							<?php
							$cfiles++;
							break;
						}
						if ($cfiles<1){
							echo '<div class="judul-gale"><h4>Tidak terdapat profpic saat ini</h4></div>';
							?>
							<form action="<?php echo $config['home_url']."backend/addsanggarkomupp"?>" method="post" enctype="multipart/form-data">
								<input type="hidden" name="idk" value="<?php echo $res['idSanggar']; ?>"
								<div>Profpic : <input type='file' name='pp'/></div>
								<div><input class="btn" type="submit" value="Tambah" name="tambah" /></div>
							</form>
						<?php } ?>
					<h4 onclick="javascript:showHide('foto<?php echo $res['idSanggar']; ?>');">Foto++</h4>
					<div id="foto<?php echo $res['idSanggar']; ?>" style="display:none">
						<form action="<?php echo $config['home_url']."backend/addsanggarkomufoto"?>" method="post" enctype="multipart/form-data">
							<input type="hidden" name="idk" value="<?php echo $res['idSanggar']; ?>" />
							<div>Gambar : <input type='file' name='gambar'/></div>
							<div><input class="btn" type="submit" value="Tambah" name="tambah" /></div>
						</form>
						<div><?php
							$uploaddir = $config['image_path'].'sanggar'.DIRECTORY_SEPARATOR."pre".DIRECTORY_SEPARATOR;
							$cfiles = 0;
							$regex = $uploaddir.$res['idSanggar']."-*";
							$limitedext = array("jpg","jpeg","png","bmp");
							//FILTER
							foreach (glob($regex) as $files) {
								$getFile = explode(DIRECTORY_SEPARATOR,$files);
								$file = $getFile[count($getFile)-1];
								$getExt = explode('.',$file);
								$file_ext = $getExt[count($getExt)-1];
								if (in_array($file_ext,$limitedext)) {
									?>
									<div style="float:left">
										<div class='gallery-thumb' id='gallery-thumb-<?php echo $cfiles; ?>' style='max-width:80px;max-height:50px;overflow:hidden;'>
											<img id="gallery-thumb-img-<?php echo $cfiles; ?>" src="<?php echo $config['image_url']."sanggar/pre/".$file; ?>" alt="<?php echo $file; ?>" />
										</div>
										<div align="center">
											<div><a class="ahapus" href="<?php echo $config['home_url']."backend/delsanggarkomufoto?img=$file"?>">(X)</a></div>
										</div>
									</div>
									<?php
									$cfiles++;
								}
							}
							if ($cfiles<1){
								echo '<div class="judul-gale"><h5>Tidak terdapat foto saat ini</h5></div>';
							}?>
							<div style="clear:both"></div>
						</div>
					</div>
				<?php
				echo "</div></li>";
			}
			echo "</ul>";
			?>
		</div>
	</div>
    <?php
    view_backend_footer($config, $param);
}
